using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Text;
using Instedd.Labs.Forms.Library;

public partial class GetSurvey : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.ClientScript.RegisterStartupScript(typeof(string), "LoadDocument", "LoadDocument()");
        //this.ClientScript.

        this.formVersion.Value = SurveyManager.GetInstance().FormVersion;

        string surveyId = this.Request["surveyId"];

        if (!String.IsNullOrEmpty(surveyId))
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.OmitXmlDeclaration = true;
            StringBuilder xmlContent = new StringBuilder();
            using (XmlWriter writer = XmlWriter.Create(xmlContent, settings))
            {
                XmlDocument survey = SurveyManager.GetInstance().GetSurveyById(surveyId);
                survey.WriteTo(writer);
            }

            HtmlContainerControl xml = this.FindControl("surveyXmlId") as HtmlContainerControl;
            xml.InnerHtml = xmlContent.ToString();
        }
        else
        { 
            // A new survey is shown
        }
    }

}
